package com.hsoft.zhxy.app.xtgl_02_01.controller;

import com.alibaba.fastjson.JSONObject;
import com.hsoft.zhxy.app.common.model.entity.YhglEntity;
import com.hsoft.zhxy.app.xtgl_02_01.model.query.YhglQuery;
import com.hsoft.zhxy.app.xtgl_02_01.service.YhglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@Api(tags = "xtgl_02_01 用户管理")
@Log4j2
@Validated
@RestController
@RequestMapping(value = "/xtgl/yhgl/", produces = "application/json;charset=UTF-8")
public class YhglController {

    @Autowired
    private YhglService yhglService;

    @ApiOperation(value = "查询单条数据", notes = "查询单条数据")
    @GetMapping("findOne")
    public JSONObject findOne(YhglEntity yhglEntity) {
        return yhglService.findOne(yhglEntity);
    }

    @ApiOperation(value = "查询列表数据", notes = "查询列表数据")
    @GetMapping("findList")
    public JSONObject findList(YhglEntity yhglEntity) {
        return yhglService.findList(yhglEntity);
    }

    @ApiOperation(value = "查询分页列表数据", notes = "查询分页列表数据")
    @GetMapping("findListByPage")
    public JSONObject findListByPage(YhglEntity yhglEntity, long page, long pageSize) {
        return yhglService.findListByPage(yhglEntity, page, pageSize);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("add")
    public JSONObject add(@RequestBody @Valid YhglEntity yhglEntity) {
        return yhglService.add(yhglEntity);
    }

    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("update")
    public JSONObject update(@RequestBody @Valid YhglEntity yhglEntity) {
        return yhglService.update(yhglEntity);
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("delete")
    public JSONObject delete(@RequestBody YhglEntity yhglEntity) {
        return yhglService.delete(yhglEntity);
    }

    @ApiOperation(value = "获取用户信息和部门信息", notes = "获取用户信息和部门信息")
    @GetMapping("findListOfYhxxAndYhbmByPage")
    public JSONObject findListByPageOfYhxxAndYhbm(@Valid YhglQuery yhglQuery) {
        log.info(yhglQuery.toString());
        return yhglService.findListOfYhxxAndYhbmByPage(yhglQuery);
    }
}
